package com.teamwork.demo.service.impl;

import com.teamwork.demo.entity.User;
import com.teamwork.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService implements com.teamwork.demo.service.UserService {
    @Autowired
    public UserMapper userMapper;


    @Override
    public boolean isUserRegistered(Integer id) {
        return userMapper.findById(id).isPresent();
    }
    @Override
    public User registerNewUser(User user) {
        if (userMapper.findByUphone(user.getUphone()) != null) {
            throw new IllegalArgumentException("User with this phone number already exists");
        }
        return userMapper.save(user);
    }
    @Override
    public boolean islogin( String uphone, String password) {
        User user = userMapper.findByUphone(uphone);
        if (user != null && password.equals(user.getUpassword())) {
            return true;
        } else {
            return false;
        }
    }
    @Override
    public User getUserByPhone(String uphone) {
        User user = userMapper.findByUphone(uphone);
        return user;
    }





}
